package com.hjk.common.response.exception;


import com.hjk.common.response.enums.BaseREnum;
import com.hjk.common.response.enums.ExceptionEnum;
import com.hjk.common.utils.date.MyDateTimeUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @date 2019/10/4 0004 -- 20:17
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class HjkException extends RuntimeException {

    /**
     *   把异常处理状态码和信息 传进来
     */
    private ExceptionEnum exceptionEnum;

    private Integer status;

    private String date = MyDateTimeUtils.formatDefaultDate();

    public HjkException(Integer status, String message) {
        super(message);
        this.status = status;

    }

    public HjkException(ExceptionEnum exceptionEnum) {
        super(exceptionEnum.getMessage());
        this.status = exceptionEnum.getCode();
    }

    public HjkException(BaseREnum exceptionEnum) {
        super(exceptionEnum.getMessage());
        this.status = exceptionEnum.getCode();
    }

    public static  HjkException error(BaseREnum exceptionEnum) {
        return new HjkException(exceptionEnum.getCode(),exceptionEnum.getMessage());
    }

    public static  HjkException error(BaseREnum exceptionEnum,String message) {
        return new HjkException(exceptionEnum.getCode(),message);
    }
}
